#pragma once
#include <iostream>
#include <pthread.h>
using namespace std;

class Mutex
{
public:
    Mutex(pthread_mutex_t *mtx) : pmtx_(mtx)
    {}
    void lock()
    {
        // cout << "要进行加锁了" << endl;
        pthread_mutex_lock(pmtx_);
    }
    void unlock()
    {
        // cout << "要进行解锁了" << endl;
        pthread_mutex_unlock(pmtx_);
    }
    ~Mutex()
    {}
private:
    pthread_mutex_t *pmtx_;
};

// RAII风格的加锁方式
class LockGuard
{
public:
    LockGuard(pthread_mutex_t *mtx) : mtx_(mtx)
    {
        mtx_.lock();
    }
    ~LockGuard()
    {
        mtx_.unlock();
    }

private:
    Mutex mtx_;
};
